package PlotPourri.Database;

import PlotPourri.BandName;
import PlotPourri.Observation;
import PlotPourri.Star;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class DatabaseKepler extends StarDatabase {

    public DatabaseKepler(File main) {
        super(main);
        Scanner sc = null;
        try {
            sc = new Scanner(main);
        } catch (FileNotFoundException ex) {
            System.err.print(ex + "\n");
        }
        if (sc != null) {
            int name = 0;
            while (sc.hasNextLine()) {
                String line = sc.nextLine();
                if (line.startsWith("#")) continue;
                Star star = new Star(BandName.V, name);
                star.setPeriod(Double.parseDouble(line.split("\\s+")[1]));
                String full = main.getPath().split("Kepler.dat")[0] + File.separatorChar + "data" + File.separatorChar + line.split("\\s+")[0] + ".dat";
                Observation datfile = new Observation(full, name++);
                datfile.setPhasePosition(-1);
                datfile.setMagnitudePosition(1);
                datfile.setErrorPosition(-1);
                datfile.setJulianDatePosition(0);
                datfile.setPeriod(star.getPeriod());
                star.getBand(BandName.V).add(datfile);
                if (!containsKey(name)) put(star.getName(), star);
            }
            sc.close();
        }
    }
}
